package com.situ.orderingsystem.utils;

public class PaginateInfo {
    private int pageNo;
    private final int pageSize;
    private long count;//总记录数
    private int pages;//总页数
    private int navfirst;
    private int navlast;
    private final int navPages = 7;//总页数
    public PaginateInfo(int pageNo, int pageSize) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
    }

    public int getPageNo() {
        return pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public int getLimit(){
        return this.pageSize;
    }
    public int getOffset(){
        return (pageNo -1 )*pageSize;
    }

    @Override
    public String toString() {
        return "PaginateInfo{" +
                "pageNo=" + pageNo +
                ", pageSize=" + pageSize +
                ", count=" + count +
                ", pages=" + pages +
                '}';
    }

    public long getCount() {
        return count;
    }

    public void setCount(long count) {
        this.count = count;

        this.pages =(int) (this.count / this.pageSize);
        if(this.count % this.pageSize >0){
            this.pages++;
        }
        if(this.pageNo > pages){
            pageNo =pages;
        }
        if(this.pageNo < 1){
            pageNo =1;
        }

        int half = this.navPages / 2;
        navfirst = pageNo - half;
        if(navfirst <= 0){
            navfirst = 1;
        }
        navlast = navfirst + navPages -1 ;
        if(navlast > pages){
            navlast = pages;
            navfirst =navfirst - navPages +1;
            if(navfirst <= 0){
                navfirst = 1;
            }
        }

    }
    public int getPages() {
        return pages;
    }

    public int getNavfirst() {
        return navfirst;
    }

    public int getNavlast() {
        return navlast;
    }

    public int getNavPages() {
        return navPages;
    }
}
